<% layout('/layouts/default.html', {title: '待发货订单列表', libs: ['dataGrid']}){ %>
<div class="main-content">
	<div class="box box-main">
		<div class="box-header">
			<div class="box-title">
				<i class="fa fa-list-alt"></i> ${text('待发货订单列表')}
			</div>
			<div class="box-tools pull-right">
			
			<a href="#" class="btn btn-default" id="btnDelUser" title="确定拣货"><i class="fa fa-filter"></i> 批量确定拣货</a>
			<a href="#" class="btn btn-default" id="btnSearch" title="${text('查询')}"><i class="fa fa-filter"></i> ${text('查询')}</a>
			
			</div>
		</div>
		<div class="box-body">
			<#form:form id="searchForm" model="${ztGoodsOrder}" action="${ctx}/ztGoodsOrder/listData" method="post" class="form-inline hide"

					data-page-no="${parameter.pageNo}" data-page-size="${parameter.pageSize}" data-order-by="${parameter.orderBy}">

				<div class="form-group">
					<label class="control-label">${text('订单号')}：</label>
					<div class="control-inline">
						<#form:input path="order" maxlength="200" class="form-control width-120"/>
					</div>
				</div>
				
				<div class="form-group">
					<label class="control-label">${text('姓名')}：</label>
					<div class="control-inline">
						<#form:input path="name" maxlength="30" class="form-control width-120"/>
					</div>
				</div>
				
				<div class="form-group">
					<label class="control-label">${text('号码')}：</label>
					<div class="control-inline">
						<#form:input path="phone" maxlength="20" class="form-control width-120"/>
					</div>
				</div>
				
				<div class="form-group">
					<label class="control-label">${text('地址')}：</label>
					<div class="control-inline">
						<#form:input path="addr"  class="form-control width-120"/>
					</div>
				</div>
				
				<div class="form-group">
					<label class="control-label">${text('商品名')}：</label>
					<div class="control-inline">
						<#form:input path="ztGoods.title"  class="form-control width-120"/>
					</div>
				</div>
			
				<div class="form-group">
					<label class="control-label">${text('微信名')}：</label>
					<div class="control-inline">
						<#form:input path="ztAdmin.name" maxlength="200" class="form-control width-120"/>
					</div>
				</div>
				
				<div class="form-group">

					<button type="submit" class="btn btn-primary btn-sm">${text('查询')}</button>

					<button type="reset" class="btn btn-default btn-sm">${text('重置')}</button>

				</div>

			</#form:form>

			<table id="dataGrid"></table>
			<div id="dataGridPage"></div>
		</div>
	</div>
</div>

<div class="hide"><div class="input-group treeselect" id="userSelectDiv" data-url="/wewoo/a/sys/user/userSelect?userType=employee">
	<input id="userSelectCode" type="hidden" name="" value="" class="isReset"/>
	<input id="userSelectName" type="text" name="" value=""
		class="form-control  " readonly="readonly"
	/><span class="input-group-btn"><a id="userSelectButton" href="javascript:"
		class="btn btn-default "><i class="fa fa-search"></i></a>
	</span>
</div>

<% } %>
<script>


$("#userSelectButton,#userSelectName").click(function(){
	if ($("#userSelectButton").hasClass("disabled")){
		return true;
	}
	var selectData = {},
	boxWidth = $(top.window).width() - 100,
	boxHeight = $(top.window).height() - 100;
	boxWidth = boxWidth < 350 ? 350 : boxWidth;
	boxHeight = boxHeight < 250 ? 250 : boxHeight;
	if(typeof listselectGetSelectData == 'function'){
		selectData = listselectGetSelectData('userSelect');
	}else{
		var codes = $('#userSelectCode').val(), names = $('#userSelectName').val();
		if(codes != null && codes != "" && names != null && names != ""){
			var codesArr = codes.split(","), namesArr = names.split(",");
			if (codesArr && namesArr && codesArr.length == namesArr.length){
				for(var i=0; i<codesArr.length; i++) {
					selectData[codesArr[i]] = {userCode: codesArr[i], userName: namesArr[i]}
				}
			}
		}
	}
	var options = {
		type: 2,
		maxmin: true,
		shadeClose: true,
		title: '用户选择',
		area: [boxWidth+'px', boxHeight+'px'],
		content: $('#userSelectDiv').attr('data-url'),
		contentFormData: {
			checkbox: 'true',
			selectData: js.encodeUrl(JSON.stringify(selectData))
		},
		success: function(layero, index){
			if ($(js.layer.window).width() < boxWidth
				|| $(js.layer.window).height() < boxHeight){
				js.layer.full(index);
			}
		},
		btn: ['<i class="fa fa-check"></i> 确定'],
		btn1: function(index, layero){
			var win = js.layer.iframeWindow(index);
			selectData = win.getSelectData();
			if(typeof listselectCheck == 'function'){
				if (!listselectCheck('userSelect', selectData)){
					return false;
				}
			}
			if(typeof listselectSetSelectData == 'function'){
				listselectSetSelectData('userSelect', selectData);
			}else{
				var codes = [], names = [];
				$.each(selectData, function(key, value){
					codes.push(value['userCode']);
					names.push(value['userName']);
				});
		   		$('#userSelectCode').val(codes.join(',')).change();
		   		$('#userSelectName').val(names.join(',')).change();
			}
			try { $('#userSelectCode,#userSelectName').valid(); }catch(e){}
			if(typeof listselectCallback == 'function'){
				listselectCallback('userSelect', 'ok', index, layero, selectData);
			}
		}
	};
	options.btn.push('<i class="fa fa-close"></i> 关闭');
	options['btn'+options.btn.length] = function(index, layero){
		if(typeof listselectCallback == 'function'){
			listselectCallback('userSelect', 'cancel', index, layero);
		}
	};
	js.layer.open(options);
});


// 初始化DataGrid对象
$('#dataGrid').dataGrid({
	searchForm: $("#searchForm"),
	columnModel: [     
{header:'${text('订单号')}', name:'order',index:'a.order',  width:220, align:"center"},
		{header:'${text('微信名')}', name:'ztAdmin.name',index:'u10.name',  width:100, align:"center"},
		
		{header:'${text('商品名称')}', name:'ztGoods.title', index:'z.title', width:170, align:"center"},
		{header:'${text('颜色')}', name:'colorName', width:80, align:"center"},
		{header:'${text('规格')}', name:'guigeName', width:70, align:"center"},
		
		{header:'${text('数量')}', name:'numCount', index:'a.num_count', width:70, align:"center"},
		{header:'${text('商品价')}', name:'goodsPrice', index:'a.goods_price', width:100, align:"center"},
		
	
		{header:'${text('余额抵扣')}', name:'balance',index:'a.balance', width:105, align:"center"},
		{header:'${text('运费')}', name:'freight',index:'a.freight', width:95, align:"center"},
		
		{header:'${text('应付总价')}', name:'totalPrice', index:'a.totalPrice', width:120, align:"center"},      
		
		{header:'${text('收货人')}', name:'name', index:'a.name', width:150, align:"center"},
		
		{header:'${text('号码')}', name:'phone', index:'a.phone', width:100, align:"center"},
		
		{header:'${text('商品编号')}', name:'sku', index:'a.sku', width:110, align:"center"},
		{header:'${text('渠道订单')}', name:'channelorder', index:'a.channelorder', width:110, align:"center"},
		{header:'${text('渠道价')}', name:'channelprice', index:'a.channelprice', width:100, align:"center"},
	
		{header:'${text('下单时间')}', name:'orderTime', index:'a.order_time', width:160, align:"center"},
		{header:'${text('付款时间')}', name:'payTime', index:'a.pay_time', width:160, align:"center"},
		{header:'${text('状态')}', name:'orderstatus', index:'a.orderstatus', width:100, align:"center", formatter: function(val, obj, row, act){
			return js.getDictLabel(${@DictUtils.getDictListJson('zt_orderstatus_type')}, val, '${text('待付款')}', true);
		}},
		
		{header:'${text('拣货')}', name:'issign', index:'a.issign', width:110, align:"center", formatter: function(val, obj, row, act){
			return js.getDictLabel(${@DictUtils.getDictListJson('sys_yes_no')}, val, '${text('否')}', true);
		}},
		
		{header:'${text('操作')}', name:'actions', width:100,align:"center", sortable:false, title:false, formatter: function(val, obj, row, act){
			var actions = [];
			<% if(hasPermi('ztGoodsOrder:ztGoodsOrderData:edit')){ %>
				
				actions.push('<a href="${ctx}/ztGoodsOrder/form?id='+row.id+'" class="btnList" title="${text('查看订单详情')}"><i class="fa fa-navicon"></i></a>&nbsp;');

			<% } %>
			return actions.join('');
		}}
		
	],
	showCheckbox: true,
	// 加载成功后执行事件
	ajaxSuccess: function(data){
		
	}
});

$('#btnDelUser').click(function(){
	var userCodes = $('#dataGrid').dataGrid('getSelectRows');
	if (userCodes != null && userCodes.length > 0){
		js.confirm('确认要确定拣货吗？', function(){
			js.ajaxSubmit('${ctx}/ztGoodsOrder/updateList', {
				
				userRoleString: userCodes.join(',')
			}, function(data){
				js.showMessage(data.message);
				page();
			});
		});
	}else{
		js.showMessage('请在列表选中要确定拣货的订单');
	}
	return false;
});
$('#btnAddUser').click(function(){
	$('#userSelectName').click();
});
function listselectCallback(id, action, index, layero){
	if (id == 'userSelect' && action == 'ok'){
		if ($('#userSelectCode').val() != ''){
			js.ajaxSubmit('/wewoo/a/sys/role/saveAuthUser', {
				roleCode: '0007',
				userRoleString: $('#userSelectCode').val()
			}, function(data){
				js.showMessage(data.message);
				page();
			});
		}else{
			js.showMessage('没有选择要授权的用户');
		}
	}
}
</script>